package com.second.app.thread.join.join_releaselock;

import java.util.Map;

/**
 * @Author GYZ
 * <pre>
 *  通过线程a,执行线程b,线程b对象持有6s，线程c执行也持有线程b对象。
 *  目的：证明sleep不释放锁，线程c打印日志，必须要等到线程a释放b线程对象。
 * </pre>
 */
public class DD {

    public static void main(String[] args) {

        Thread b = new Thread(() -> {
            try {
                System.out.println(" b run begin timer =" + System.currentTimeMillis());
                Thread.sleep(5000);
                System.out.println(" b run end timer =" + System.currentTimeMillis());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "THREAD-B");


        Thread a = new Thread(() -> {
            try {
                synchronized (b) {
                    b.start();
                    b.join();
                    for (int i = 0; i < Integer.MAX_VALUE; i++) {
                        String newString = new String();
                        Math.random();
                    }
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "THREAD-A");

        a.start();

        Thread c = new Thread(() -> {
            synchronized (b) {
                System.out.println(" 打印了timer=" + System.currentTimeMillis());
            }
        }, "THREAD-C");
        c.start();
    }
}
